package com.bmps.springcloud.insuredmicroservice.service.accept;

import com.bmps.springcloud.insuredmicroservice.model.accept.MessageModel;
import com.bmps.springcloud.insuredmicroservice.repository.accept.master.InsuranceAcceptRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author lyw
 * @date 2019/07/24
 */
@Service
public class InsuranceAcceptServiceImpl implements InsuranceAcceptService {

    private final InsuranceAcceptRepository insuranceAcceptRepository;

    public InsuranceAcceptServiceImpl(InsuranceAcceptRepository insuranceAcceptRepository) {
        this.insuranceAcceptRepository = insuranceAcceptRepository;
    }

    /**
     * 插入数据库
     * @param messageModel messagemode
     * @throws Exception 抛出异常
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void insertMessage(MessageModel messageModel) throws Exception {
        insuranceAcceptRepository.insertMessageAccept(messageModel);
        insuranceAcceptRepository.insertAcceptRequestAndResponseMessage(messageModel.getContNo(),
                messageModel.getMessage(),messageModel.getResponse());
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void insertMessageError(MessageModel messageModel) {
        insuranceAcceptRepository.insertMessageError(messageModel);
    }

    @Override
    public List<String> getRiskCodeList(String codeType) {
        return insuranceAcceptRepository.getRiskCodeList(codeType);
    }

    @Override
    public String getAgentComByCode(String code) {
        return insuranceAcceptRepository.getAgentComByCode(code);
    }

    @Override
    public String getAgentCom(String code) {
        return insuranceAcceptRepository.getAgentCom(code);
    }

    @Override
    public void updateAcceptPushFlag(int pushFlag,String contno, int oldPushFlag) {
        insuranceAcceptRepository.updateAcceptPushFlag(pushFlag, contno, oldPushFlag);
    }

}
